<?php
namespace Portal\Controller;
use Common\Controller\HomebaseController;

class ChooseController extends HomebaseController {
	public $Site;
	public $Coach;
	public $Lesson;
	public $Reserve;
	public $Member;
	public $Judge;
	public $Usercard;
	public $Card;
    public $Re;
	public function __construct(){
		parent::__construct();
		header("Content-type: text/html; charset=utf-8");
		$this->Site     =M('site');
		$this->Coach    =M('coach');
		$this->Lesson   =M('lesson');
		$this->Reserve  =M('reserve');
		$this->Member   =M('member');
		$this->Judge    =M('judge');
		$this->Usercard =M('usercard');
		$this->Card     =M('card');
		$this->Re       =M('re');
	}
	//场馆（默认）
	public function index(){
		$msg=$this->Site->select();
		$this->assign('msg',$msg);
		$this->display(':index');
	}
	//site存入session并跳转到order
	public function sitesession(){
		session('sitename',$_GET['site']);
		header("Location:index.php?m=Choose&a=order");
	}
	//课程
	public function order(){
		$sitename=session('sitename');
		//如果未选场馆，默认为第一个场馆
		if(empty($sitename)){
			$s=$this->Site->select();
			$sitename=$s[0]['sitename'];
		}
		//通过uid查找usercard表中的cardname，再通过cardname到card表中查找canlesson
		$ww['uid']=session('uid');
		$cardname=$this->Usercard->where($ww)->getField('cardname',true);
		//今日起七天内课程
		$where['sitename']=$sitename;
		for($j=0;$j<7;$j++){
			$where['sdate']=date("Y-m-d",strtotime("+$j days"));
			$le=$this->Lesson->where($where)->order('stime')->select();
			//1.循环找出lid对应的教练名字，2.找出还可预约多少人left
			for($i=0;$i<count($le);$i++){
				//coachname
				$w['coachid']=$le[$i]['coachid'];
				$coachname=$this->Coach->where($w)->select();
				$le[$i]['coachname']=$coachname[0]['coachname'];
				//lid
				if($cardname){		
					$le[$i]['target']="''";
					$le[$i]['href']='index.php?m=Choose&a=preorder&lid='.$le[$i]['lid'];				
				}else{
					$le[$i]['target']='#alert-new-order';
					$le[$i]['href']="''";
				}
				//left可预约人数
				$le[$i]['left']=$le[$i]['uplimit']-$le[$i]['ordered'];			
				//sdate几月几日
				$le[$i]['stime']=substr($le[$i]['stime'],0,5);
				$whw['lid']=$le[$i]['lid'];
				$whw['uid']=session('uid');
				$mr=$this->Reserve->where($whw)->select();
				if(empty($mr)||$mr[0]['status']==-1){
					//没有订单，或订单已取消，则显示"预约"
					$le[$i]['button']=array('block','none','none');
				}elseif($mr[0]['status']==1){
					//有订单且状态为“预约成功”，则显示“取消预约”
					$le[$i]['button']=array('none','block','none');
				}elseif($mr[0]['status']==2){
					//有订单且状态为“排队中”，则显示为“排队中”
					$le[$i]['button']=array('none','none','block');
				}elseif($mr[0]['status']==3){
					//有订单且状态为“已完成”，则不显示
					$le[$i]['button']=array('none','none','none');
				}
			}
			$msg[$j]=$le;
		}
		$w=date('w');
			switch($w){
				case 0:
					$week[0]="周日";
					$week[1]="周一";
					$week[2]="周二";
					$week[3]="周三";
					$week[4]="周四";
					$week[5]="周五";
					$week[6]="周六";
					break;
				case 1:
					$week[0]="周一";
					$week[1]="周二";
					$week[2]="周三";
					$week[3]="周四";
					$week[4]="周五";
					$week[5]="周六";
					$week[6]="周日";
					break;
				case 2:
					$week[0]="周二";
					$week[1]="周三";
					$week[2]="周四";
					$week[3]="周五";
					$week[4]="周六";
					$week[5]="周日";
					$week[6]="周一";
					break;
				case 3:
					$week[0]="周三";
					$week[1]="周四";
					$week[2]="周五";
					$week[3]="周六";
					$week[4]="周日";
					$week[5]="周一";
					$week[6]="周二";
					break;
				case 4:
					$week[0]="周四";
					$week[1]="周五";
					$week[2]="周六";
					$week[3]="周日";
					$week[4]="周一";
					$week[5]="周二";
					$week[6]="周三";
					break;
				case 5:
					$week[0]="周五";
					$week[1]="周六";
					$week[2]="周日";
					$week[3]="周一";
					$week[4]="周二";
					$week[5]="周三";
					$week[6]="周四";
					break;
				case 6:
					$week[0]="周六";
					$week[1]="周日";
					$week[2]="周一";
					$week[3]="周二";
					$week[4]="周三";
					$week[5]="周四";
					$week[6]="周五";
					break;
			}
		for($i=0;$i<7;$i++){
			$day[$i]=date("m.d",strtotime("+$i days"));
		}
		$this->assign('sitename',$sitename)
		->assign('msg',$msg)
		->assign('day',$day)
		->assign('week',$week);
		$this->display(':order');
	}
	//用户
	public function user(){
		//显示头像，名称，积分，昵称
		$where['uid']=session('uid');
		$m=$this->Member->where($where)->select();
		$msg=$m[0];
		$msg['nick']=urldecode($msg['nick']);
		$msg['memberpic']=$msg['memberpic'];
		$this->assign('msg',$msg);
		$this->display(':user');
	}
	//直播
	public function video(){
		$Video=M('video');
		$video=$Video->order('vtime desc')->select();
		for($i=0;$i<count($video);$i++){
			$video[$i]['vpic']=json_decode($video[$i]['vpic'],true);
			$video[$i]['picnum']=count($video[$i]['vpic']);
			$video[$i]['vtime']=date('Y-m-d H:i',$video[$i]['vtime']);
		}
		$this->assign('video',$video);
		$this->display(':video');
	}
	//周课表
	public function weekly_course(){

		$this->display(':weekly-course');
	}
	//coachid,lid,coachname存入session并跳转到course
	public function lessonsession(){
		session('lid',$_POST['lid']);
		session('coachid',$_POST['coachid']);
		session('coachname',$_POST['coachname']);
		header("Location:index.php?m=Choose&a=course");
	}
	//课程详情
	public function course(){
		//1.课程详情
		$where['lid']=session('lid');		
        $msg1=$this->Lesson->where($where)->select();
		$wh['sitename']=session('sitename');
		$msg1[0]['addr']=$this->Site->where($wh)->getField('addr');
		$msg1[0]['stime']=substr($msg1[0]['stime'],0,5);
		//2.教练详情
		$coachname=session('coachname');
		$coachid=session('coachid');
		$coachpic=urldecode($this->Coach->where("coachid='$coachid'")->getField('coachpic'));
		$this->assign('msg1',$msg1[0])
		->assign('coachname',$coachname)
		->assign('coachpic',$coachpic)
		->assign('coachid',$coachid);
		$this->display(':course');
	}
	//教练详情
	public function coach(){
		//1.教练信息
		$where1['coachid']=session('coachid');
        $msg1=$this->Coach->where($where1)->select();
		$msg1[0]['coachpic']=urldecode($msg1[0]['coachpic']);
		//2.评论信息
		$where1['comment']=array('neq','');
		$msg2=$this->Judge->where($where1)->order('judgetime desc')->limit(30)->select();
		for($i=0;$i<count($msg2);$i++){
			$msg2[$i]['judgetime']=substr($msg2[$i]['judgetime'],0,10);
		}
		//3.会员信息
		for($i=0;$i<count($msg2);$i++){
			$where2['uid']=$msg2[$i]['uid'];
			$unick=urldecode($this->Member->where($where2)->getField('nick'));
			$uimg=$this->Member->where($where2)->getField('memberpic');
			$msg2[$i]['unick']=$unick;
			$msg2[$i]['uimg']=$uimg;
		}
		$this->assign('msg1',$msg1)
		->assign('msg2',$msg2);
		$this->display(':coach');
	}
	//个人信息
	public function personal_info(){
		//where条件(根据用户uid查询对应信息)
		$where['uid']=session('uid');
        $msg=$this->Member->where($where)->find();
		$msg['nick']=urldecode($msg['nick']);
		$this->assign('msg',$msg);
		$this->display(':personal-info');
	}
	//更改个人信息
	public function changeinfo(){
		$info['name']=$_POST['name'];
		$info['tel']=$_POST['tel'];
		$info['s']=$_POST['s'];
		$where['uid']=session('uid');
		$this->Member->startTrans();
		$m=$this->Member->where($where)->save($info);
		if($m){
			$this->Member->commit();
			echo "<script>alert('修改成功！');location.href='index.php?m=Choose&a=user';</script>";
		}else{
			$this->Member->rollback();
			echo "<script>alert('修改失败或您未做任何修改！');location.href='index.php?m=Choose&a=user';</script>";
		}
	}
	//我的课程
	public function order_complete(){
		//where条件(根据用户openid查询对应信息)
		$where1['uid']=$where2['uid']=$where3['uid']=session('uid');
		$where1['status']=1;
        $msg1=$this->Reserve->where($where1)->order('ordertime desc')->select();
		for($i=0;$i<count($msg1);$i++){
			$where1['lid']=$msg1[$i]['lid'];
			$m=$this->Lesson->where($where1)->select();
			$ms1[$i]=$m[0];//已预约课程详情
			$coachid=$ms1[$i]['coachid'];
			$c=$this->Coach->where("coachid='$coachid'")->select();
			$ms1[$i]['coachname']=$c[0]['coachname'];//该课程教练姓名
			$ms1[$i]['left']=$ms1[$i]['uplimit']-$ms1[$i]['ordered'];
			$ms1[$i]['stime']=substr($ms1[$i]['stime'],0,5);
			$ms1[$i]['sdate']=substr($ms1[$i]['sdate'],5,2)."月".substr($ms1[$i]['sdate'],8)."日";
		}
		//var_dump($ms1);
		//die();
		$where2['status']=2;
		$msg2=$this->Reserve->where($where2)->order('ordertime desc')->select();
		for($i=0;$i<count($msg2);$i++){
			$where2['lid']=$msg2[$i]['lid'];
			$m=$this->Lesson->where($where2)->select();
			$ms2[$i]=$m[0];//排队课程详情
			$coachid=$ms2[$i]['coachid'];
			$c=$this->Coach->where("coachid='$coachid'")->select();
			$ms2[$i]['coachname']=$c[0]['coachname'];//该课程教练姓名
			$ms2[$i]['left']=$ms2[$i]['uplimit']-$ms2[$i]['ordered'];
			$ms2[$i]['stime']=substr($ms2[$i]['stime'],0,5);
			$ms2[$i]['sdate']=substr($ms2[$i]['sdate'],5,2)."月".substr($ms2[$i]['sdate'],8)."日";
		}
		//该用户已完成课程
		$where3['status']='3';
		$msg3=$this->Reserve->where($where3)->order('ordertime desc')->limit(20)->select();
		for($i=0;$i<count($msg3);$i++){
			$where3['lid']=$msg3[$i]['lid'];
			$m=$this->Lesson->where($where3)->select();
			$ms3[$i]=$m[0];//排队课程详情
			$coachid=$ms3[$i]['coachid'];
			$c=$this->Coach->where("coachid='$coachid'")->select();
			$ms3[$i]['coachname']=$c[0]['coachname'];//该课程教练姓名
			$ms3[$i]['stime']=substr($ms3[$i]['stime'],0,5);
			//判断是否签到
			if($msg3[$i]['sign']==1){
				$ms3[$i]['button']=array('block','none','none','none');
			}else{
				//已签到，判断是否评价
				if($msg3[$i]['judge']==1){
					//未评价
					$ms3[$i]['button']=array('none','block','block','none');
				}else{
					//已评价
					$ms3[$i]['button']=array('none','none','block','block');
				}
			}
		}
		$this->assign('ms1',$ms1)
		->assign('ms2',$ms2)
		->assign('ms3',$ms3);
		$this->display(':order-complete');
	}
	//我的会员卡
	public function mycard(){
		//where条件(根据用户openid查询对应信息)
		$where['uid']=$w['uid']=session('uid');
        $msg=$this->Usercard->where($where)->select();
		$w['deadtime']=array('lt',intval(time()));
		$msg2=$this->Usercard->where($w)->delete();
		for($i=0;$i<count($msg);$i++){
			$where['cardname']=$msg[$i]['cardname'];
			$msg3=$this->Card->where($where)->getField('canlesson');
			$msg[$i]['canlesson']=$msg3;
			$msg[$i]['deadtime']=date('Y-m-d',$msg[$i]['deadtime']);
		}
		$this->assign('msg',$msg);
		$this->display(':mycard');
	}
	//lid存入session并跳转到reserve
	public function preorder(){
		//1.判断该用户有无权限？是否是会员？
		//2.判断订单中未完成课程是否有三个以上？
		session('lid',$_GET['lid']);
		header("Location:index.php?m=Choose&a=reserve");
	}
	//预约(生成订单)
	
	public function reserve(){
		$where['lid']=session('lid');
		$msg1=$this->Lesson->where($where)->select();
		$left=$msg1[0]['uplimit']-$msg1[0]['ordered'];
		//通过uid查找usercard表中的cardname，再通过cardname到card表中查找canlesson
		$ww['uid']=session('uid');
		$cardname=$this->Usercard->where($ww)->getField('cardname',true);
			//判断日期
			$d=str_replace('-','',$msg1[0]['sdate'])-date('Ymd');//大于0则可以预约，小于0不能预约，等于0则判断可否预约
			$h=str_replace(':','',substr($msg1[0]['stime'],0,5))-date('Hi');//小于2小时则在开课2小时以内
			if($d<0){
				echo "<script>alert('课程开始后不能预约！');location.href='index.php?m=Choose&a=order';</script>";
			}
			elseif($d==0&&$h<=0){
				echo "<script>alert('课程开始后不能预约！');location.href='index.php?m=Choose&a=order';</script>";
			}else{
				$ifcl=false;
				for($i=0;$i<count($cardname);$i++){
					$cn['cardname']=$cardname[$i];
					$cmsg[$i]=$this->Card->where($cn)->getField('canlesson');
					$cmsg2[$i]=$this->Card->where($cn)->getField('cansite');
					if(strstr($cmsg[$i],$msg1[0]['lessontype'])&&strstr($cmsg2[$i],$msg1[0]['sitename'])){
						$ifcl=true;
						break;//判断$ifcl有权限则跳出循环
					}
				}
				//判断会员拥有的卡能否预约该课程
				if($ifcl==false){
					echo "<script>alert('场馆或课程类型限制，您不能预约该课程！');location.href='index.php?m=Choose&a=order';</script>";
				}else{
				//判断是否有3次未签到课程
				$sign3['uid']=session('uid');
				$unsign=$this->Member->where($sign3)->getField('unsignday');
				//如果有该值且此时在该时间段内，则不能约课
				if($unsign&&($unsign>date('U'))){
					echo "<script>alert('您有三次预约课程未签到，一周内不能预约！');</script>";
				}else{
				//判断是否有未评价课程
					$jdwhere['uid']=session('uid');
					$jdwhere['status']=3;//课程已完成
					$jdwhere['sign']=2;//课程已签到
					$jdwhere['judge']=1;//课程未评价				
					$ifjudge=$this->Reserve->where($jdwhere)->getField('judge');
					if($ifjudge){
						echo "<script>alert('有课程未评价，请先评价！');location.href='index.php?m=Choose&a=order_complete';</script>";
					}else{
						//已评价，判断是否已预约
						$where['uid']=session('uid');//需要获取用户uid,where['uid'],where['lid']
						$msgp=$this->Reserve->where($where)->select();
						if($msgp){
							echo "<script>alert('您已经预约该课程！');location.href='index.php?m=Choose&a=order';</script>";
						}else{
							//判断人数是否已满
							if($left==null||$left==0||$left<0){
								//已满，需要排队
								$data['lid']=session('lid');
								$data['uid']=session('uid');
								$data['status']=2;//排队状态
								$data['ordertime']=date("Y-m-d h:i:s");
								$this->Reserve->startTrans();
								$msg=$this->Reserve->add($data);
								if($msg){
									$this->Reserve->commit();
									echo "<script>alert('排队中！');location.href='index.php?m=Choose&a=order_complete';</script>";
								}else{
									$this->Reserve->rollback();
									echo "<script>alert('排队失败,请稍后再试！');location.href='index.php?m=Choose&a=order';</script>";
								}
							}else{
								//未满,预约成功
								$data['status']=1;
								$data['lid']=$where['lid'];
								$data['uid']=$where['uid'];
								$data['ordertime']=date("Y-m-d h:i:s");
								$this->Reserve->startTrans();
								$msg=$this->Reserve->add($data);//添加订单
								$update['ordered']=$msg1[0]['ordered']+1;
								$wh['lid']=$where['lid'];
								$msg2=$this->Lesson->where($wh)->save($update);//ordered已预约人数+1
								if($msg2&&$msg){
									$this->Reserve->commit();
									echo "<script>alert('预约成功！');location.href='index.php?m=Choose&a=order_complete';</script>";
								}else{
									$this->Reserve->rollback();
									echo "<script>alert('预约失败,请稍后再试！');location.href='index.php?m=Choose&a=order';</script>";
								}
							}
						}
					}	
				}
			}
		}	
	}
	//lid存入session并跳转到cancel
	
	public function precancel(){
		session('lid',$_GET['lid']);
		header("Location:index.php?m=Choose&a=cancel");
	}
	//取消预约(取消预约)
	public function cancel(){
		$where['lid']=$lid=session('lid');
		$msg1=$this->Lesson->where($where)->select();
		//判断日期
		$d=str_replace('-','',$msg1[0]['sdate'])-date('Ymd',time());//大于0则可以取消，小于0不能取消，等于0则判断可否取消
		$h=str_replace(':','',substr($msg1[0]['stime'],0,5))-date('Hi');
		//小于100则在开课1小时以内
		if($d<0){
			echo "<script>alert('课程已结束,不能取消！');location.href='index.php?m=Choose&a=order_complete';</script>";
		}elseif($d==0&&$h<=100){
			echo"<script>alert('开课前1小时不能取消！');location.href='index.php?m=Choose&a=order_complete';</script>";
		}else{
			$where['uid']=session('uid');//需要获取用户uid,此时条件为where['lid']和where['uid']
			$status=$this->Reserve->where($where)->getField('status');
			//判断订单status
			if($status==2){
				//排队中的订单，直接删除
				$this->Reserve->startTrans();
				$msg2=$this->Reserve->where($where)->delete();
				if($msg2){
					$this->Reserve->commit();
					echo "<script>alert('取消成功！');location.href='index.php?m=Choose&a=order_complete';</script>";
				}else{
					$this->Reserve->rollback();
					echo "<script>alert('取消失败，请稍后再试！');location.href='index.php?m=Choose&a=order_complete';</script>";
				}
			}elseif($status==1){
				//删除预约成功的订单
				$this->Reserve->startTrans();
				$msg2=$this->Reserve->where($where)->delete();
				//判断删除是否成功
				if($msg2){
					//根据lid取出和status取出排队的人
					$where2['lid']=$where['lid'];
					$where2['status']=2;
					$wait=$this->Reserve->where($where2)->order('ordertime')->limit(1)->select();
					//第一个排队的人
					if($wait){
						//若有人在排队，则更改第一个排队订单的status=1
						$where3['reid']=$wait[0]['reid'];
						$waitsave=$this->Reserve->where($where3)->setField('status','1');
						if($waitsave){
							$msgreid=$wait[0]['reid'];
							$this->sendmsg($msgreid);
							$this->Reserve->commit();
							echo "<script>alert('取消成功！');location.href='index.php?m=Choose&a=order_complete';</script>";
						}else{
							$this->Reserve->rollback();
							echo "<script>alert('取消失败，请稍后再试！');location.href='index.php?m=Choose&a=order_complete';</script>";
						}
					}else{
						//若没人排队
						$m['ordered']=$msg1[0]['ordered']-1;
						$msg3=$this->Lesson->where("lid='$lid'")->save($m);//ordered已订人数-1
						if($msg3){
							$this->Reserve->commit();
							echo "<script>alert('取消成功！');location.href='index.php?m=Choose&a=order_complete';</script>";
						}else{
							$this->Reserve->rollback();
							echo "<script>alert('取消失败，请稍后再试！');location.href='index.php?m=Choose&a=order_complete';</script>";
						}
					}
					
				}else{
					$this->Reserve->rollback();
					echo "<script>alert('取消失败，请稍后再试！');location.href='index.php?m=Choose&a=order_complete';</script>";
				}
			}
		}
	}
	//发送短信
	public function sendmsg($msgreid){
		vendor('alidayuSendMsgSDK.TopSdk');
		$Reserve= M('reserve');
		$Member = M('member');
		$Lesson = M('lesson');
		$appkey = '23468650';
		$secret = '5feaf57ca580c21b9c214e3c62a3c10d';
		//配置短息内容
		$where['reid']=$msgreid;
		$where1['uid']=$Reserve->where($where)->getField('uid');
		$where2['lid']=$Reserve->where($where)->getField('lid');
		$memberinfo=$Member->where($where1)->find();
		$name=$memberinfo['name'];
		$tel=$memberinfo['tel'];
		$lessoninfo=$Lesson->where($where2)->find();
		$sdate=substr($lessoninfo['sdate'],5,2)."月".substr($lessoninfo['sdate'],8,2)."日";
		$stime=substr($lessoninfo['stime'],0,5);
		$sitename=$lessoninfo['sitename'];
		$lesson=$lessoninfo['lesson'];
		$c = new \TopClient;
		$c->appkey = $appkey;
		$c->secretKey = $secret;
		$req = new \AlibabaAliqinFcSmsNumSendRequest;
		$req->setExtend("123456");
		$req->setSmsType("normal");
		$req->setSmsFreeSignName("如释瑜伽");
		$req->setSmsParam("{\"name\":\"$name\",\"sdate\":\"$sdate\",\"stime\":\"$stime\",\"lesson\":\"$lesson\"}");
		$req->setRecNum("$tel");
		$req->setSmsTemplateCode("SMS_17955003");
		$resp = $c->execute($req);
	}
	//lid存入session并跳转到course_judge
	public function prejudge(){
		session('lid',$_GET['lid']);
		header("Location:index.php?m=Choose&a=course_judge");
	}
	//评论页面
	public function course_judge(){
		$where['lid']=session('lid');
		$coachid=$this->Lesson->where($where)->getField('coachid');
		$where2['coachid']=$coachid;
		$coachpic=urldecode($this->Coach->where($where2)->getField('coachpic'));
		$coachname=$this->Coach->where($where2)->getField('coachname');
		$this->assign('coachname',$coachname)
		->assign('coachpic',$coachpic);
		$this->display(':course-judge');
	}
	
	//提交的评论到judgecommit处理
	public function judgecommit(){
		//dump($_POST);
		//die();
		$where1['lid']=$where2['lid']=$where3['lid']=$where4['lid']=session('lid');
		$score=$_POST['score'];
		$judgecomment=$_POST['judgecomment'];
		$this->Lesson->startTrans();
		$msg1=$this->Lesson->where($where1)->select();
		//根据lid和uid查找reid、coachid、uid，存入judge表
		$where2['uid']=session('uid');
		$data2['reid']=$this->Reserve->where($where2)->getField('reid');
		$data2['coachid']=$msg1[0]['coachid'];
		$data2['comment']=$judgecomment;
		$data2['point']=$score;
		$data2['uid']=$where2['uid'];
		$msg3=$this->Judge->add($data2);
		//dump($msg3);
		//die();
		//添加score和total+1，存入coach表
		$where3['coachid']=$msg1[0]['coachid'];
		$msg4=$this->Coach->where($where3)->select();
		$data3['total']=$msg4[0]['total']+1;
		$data3['score']=$msg4[0]['score']+$score;
		$msg5=$this->Coach->where($where3)->save($data3);
		//修改评论标志位judge，存入reserve表
		$where4['reid']=$data2['reid'];
		$data4['judge']=2;
		$msg6=$this->Reserve->where($where4)->save($data4);
		if($msg3&&$msg5&&$msg6){
			$this->Lesson->commit();
			echo "<script>alert('提交成功！');location.href='index.php?m=Choose&a=order_complete';</script>";
		}else{
			$this->Lesson->rollback();
			echo "<script>alert('提交失败！');location.href='index.php?m=Choose&a=order_complete';</script>";
		}
	}
    //商城
	public function store(){
		header("Location:http://www.zhaijiamai.com/wap/home.php?id=151");
	}
	//非会员约课信息登记
	public function noMemReg(){
		$info['nomemname']=$_POST['nomemname'];
		$info['nomemtel']=$_POST['nomemtel'];
		$where['uid']=session('uid');
		$info['subtime']=date('U');
		$info['lid']=$_POST['nomemlid'];
		//查询非会员免费预约时间
		$msg1=$this->Member->where($where)->getField('try');
		if($msg1==0){
			echo "<script>alert('非会员只能体验预约一次！');location.href='index.php?m=Choose&a=order';</script>";
		}else{
			$this->Member->startTrans();
			$msg2=$this->Member->where($where)->setField('try',0);
			$msg3=$this->Re->add($info);
			if($msg2&&$msg3){
				$this->Member->commit();
				echo "<script>alert('信息已提交，我们会尽快与您联系！');location.href='index.php?m=Choose&a=order';</script>";
			}else{
				$this->Member->rollback();
				echo "<script>alert('预约失败，请稍后再试！');location.href='index.php?m=Choose&a=order';</script>";
			}
		}
	}

}
